﻿using System;
using System.Data.SqlClient;
using System.Transactions;
using Skyhook.TransactionControl.Objects;
using TransactionManager = Skyhook.TransactionControl.Objects.TransactionManager;

namespace Skyhook.TransactionControl {
    public partial class _Default : BasePage {
        protected void Page_Load(object sender, EventArgs e) {

        }

        protected void cmdRunTransactionInline_Click(object sender, EventArgs e)
        {
            ExampleObject1.DoWork();
            ExampleObject2.DoWork();
            ExampleObject3.DoWork();

            TransactionManager.Commit();

            ////Create a committable transaction
            //CommittableTransaction tx = new CommittableTransaction();

            //var myConnection = new SqlConnection("server=(local)\\SQLExpress;Integrated Security=SSPI;database=northwind");
            //var myCommand = new SqlCommand();

            ////Open the SQL connection
            //myConnection.Open();

            ////Give the transaction to SQL to enlist with
            //myConnection.EnlistTransaction(tx);

            //myCommand.Connection = myConnection;

            //try {

            //    // Restore database to near it's original condition so sample will work correctly.
            //    myCommand.CommandText = "DELETE FROM Region WHERE (RegionID = 100) OR (RegionID = 101)";
            //    myCommand.ExecuteNonQuery();

            //    // Insert the first record.
            //    myCommand.CommandText = "Insert into Region (RegionID, RegionDescription) VALUES (100, 'MidWestern')";
            //    myCommand.ExecuteNonQuery();

            //    // Insert the second record.
            //    myCommand.CommandText = "Insert into Region (RegionID, RegionDescription) VALUES (101, 'MidEastern')";
            //    myCommand.ExecuteNonQuery();

            //    tx.Commit();
            //}
            //catch {
            //    tx.Rollback();
            //}
            //finally {
            //    myConnection.Close();
            //    tx = null;
            //}
        }
    }
}

